package net.bwie.realtime.jtp.Rpfunction;

import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.functions.windowing.WindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

/**
 * 简介说明:
 *
 * @author: LiLi
 * @date: 2025/05/28 10:56:45
 * @version: 1.0
 */
public class PromotionWindowFunction implements WindowFunction<Tuple3<String, Double, Long>, String, String, TimeWindow> {

    private FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");

    @Override
    public void apply(String string,
                      TimeWindow window,
                      Iterable<Tuple3<String, Double, Long>> input,
                      Collector<String> out) throws Exception {

        Tuple3<String, Double, Long> next = input.iterator().next();


        String windowStartTime = format.format(window.getStart());
        String windowEndTime = format.format(window.getEnd());
        //格式化输出
        String output = windowStartTime + "," + windowEndTime
                + "," + next.f0 + "," +next.f1+","+next.f2+","+
                System.currentTimeMillis();

        out.collect(output);
    }
}
